//
//  YHMainViewController.swift
//  新浪
//
//  Created by lcc on 16/5/10.
//  Copyright © 2016年 lcc. All rights reserved.
//

import UIKit

class YHMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let yhTabBar = YHTabBar()
        
        yhTabBar.yhDelegate = self
        
        yhTabBar.composeButtonClosure = {[weak self] in
            print("点击了加号按钮---")
        }
        
        //使用kvc设置只读属性
        setValue(yhTabBar, forKey: "tabBar")
        
//        self.tabBar = yhTabBar
        
        addChildViewController(YHDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(YHHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(YHMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(YHProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
        
    }
    
    
    func addChildViewController(childController: UIViewController,title: String,imageName: String) {
        
        //设置tabBar选中颜色
        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        //设置title和imageName
        childController.tabBarItem.title = title
        childController.navigationItem.title = title
        //修改统一文字
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")
        
        //修改文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        
        //设置文字大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(14)], forState: .Normal)
        
        //添加子控制器
        let nav = UINavigationController(rootViewController: childController)
        addChildViewController(nav)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */
}
extension YHMainViewController:yhTabBarDelegate {
    func didSelectedComposeButton() {
    
        print("我是通过代理方法调用过来的")
    }

}
